# coding=utf-8
"""used for server hide db key
"""

import json
from Crypto.Cipher import AES
from Crypto import Random
import binascii
import base64
import uuid

def get_mac_address(): 
    mac=uuid.UUID(int = uuid.getnode()).hex[-12:] 
    return ":".join([mac[e:e+2] for e in range(0,11,2)])

def padding_aes(str_plain):
	fs = str_plain + '1'
	x = len(fs) % 16
	if x != 0:
		fs_pad = fs + '0'*(16 - x)
	return fs_pad
print "----gen key ---"

verify_data_code="ak47"
db_sec_code=b"12345678"
mac_ip=get_mac_address()
print "mac:"+mac_ip


print "----work ---"
db_sec_code = 'ok'+ db_sec_code 
mode=AES.MODE_CBC
mac_ip_iv = Random.new().read(AES.block_size)
mac_ip_aes=AES.new(padding_aes(mac_ip), mode,mac_ip_iv)

verify_data_code_aes=AES.new(padding_aes(verify_data_code), mode,padding_aes(verify_data_code))

verify_data = {}
verify_data['db_sec_code_mac_ip'] =base64.b64encode(mac_ip_aes.encrypt(padding_aes(db_sec_code))) 
verify_data['mac_ip_iv'] = base64.b64encode(mac_ip_iv)
verify_data['mod_name'] = "sec_mode"
verify_data_str = json.dumps(verify_data)
print verify_data_str

verify_data_str_encoded=base64.b64encode(verify_data_code_aes.encrypt(padding_aes(verify_data_str))) 

print verify_data_str_encoded
